<template>
	<view class="mainpadding2">
		<view class="mainpadding_top ffffff radius flexbetween">
			<view class="main_size bold hei_text">分紅比例</view>
			<input type="number" placeholder="請輸入" v-model="fy_rate" class="textright">
		</view>
		<view class="ffffff mainpadding_top flexbetween radius" @click="messageTime.timeShow=true;timevalue=0">
			<view class="hei_text bold titletext">分紅開始時間</view>
			<view class="flexright">
				<input type="text" class="hei_text main_size bold margin_right1" style="text-align: right;" disabled=""
					v-model="fy_starttime" placeholder="請選擇開始時間">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="ffffff mainpadding_top flexbetween radius" @click="messageTime.timeShow=true;timevalue=1">
			<view class="hei_text bold titletext">分紅結束時間</view>
			<view class="flexright">
				<input type="text" class="hei_text main_size bold margin_right1" style="text-align: right;" disabled=""
					v-model="fy_endtime" placeholder="請選擇結束時間">
				<u-icon name="arrow-right" color="#999" size="16"></u-icon>
			</view>
		</view>
		<view class="flexbetween ffffff mainpadding_top radius">
			<view class="hei_text bold titletext">分紅開關</view>
			<u-switch inactiveColor="rgb(230, 230, 230)" v-model="fy_open" activeColor="#feb800"></u-switch>
		</view>
		<view class="posibottom mainpadding2">
			<view class="submitbtn" @click="submit">確定</view>
		</view>
		<timePicker :messageTime="messageTime" @timeConfirm="timeConfirm"></timePicker>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				fy_rate: "",
				timevalue: 0,
				fy_starttime: "",
				fy_endtime: "",
				messageTime: {
					timeShow: false,
					title: "選擇時間",
					mode: "datetime", //date日期，datetime年月日时分秒，time時間，year-month年月
				},
				fy_open:false
			}
		},
		onLoad() {
			this.getInfo()
		},
		methods: {
			getInfo() {
				this.http.request("/api/shop/Shopdeail", "POST", {
					shop_id: uni.getStorageSync("shop_id"),
				}).then(res => {
					this.fy_rate = res.data.fy_rate
					this.fy_starttime = res.data.fy_starttime_text
					this.fy_endtime = res.data.fy_endtime_text
					this.fy_open = res.data.fy_open==1?true:false
				})
			},
			timeConfirm(e) {
				if (this.timevalue == 0) {
					this.fy_starttime = e
				}
				if (this.timevalue == 1) {
					this.fy_endtime = e
				}
			},
			async submit() { //提交
				if (this.fy_rate == "") {
					this.http.toast("請輸入分紅比例！")
					return false
				}
				if (this.fy_starttime == "") {
					this.http.toast("請選擇分紅開始時間！")
					return false
				}
				if (this.fy_endtime == "") {
					this.http.toast("請選擇分紅開始時間！")
					return false
				}
				let data = {
					shop_id: uni.getStorageSync("shop_id"),
					fy_rate: this.fy_rate,
					fy_starttime: Number(new Date(this.fy_starttime)) / 1000,
					fy_endtime: Number(new Date(this.fy_endtime)) / 1000,
					fy_open:this.fy_open?1:0
				}
				let res = await this.http.request("/api/shop/Shopedit", "POST", data)
				if (res.code == 1) {
					this.http.toast("修改成功");
					setTimeout(() => {
						uni.navigateBack(1)
					}, 500)
				} else {
					this.http.toast(res.msg);
				}
			}
		}
	}
</script>

<style>

</style>